/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Hotels;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MrKoi
 */
public class DALtbl_Hotels extends BaseConnection {
    CallableStatement clbStm=null;
    ResultSet rs=null;    
      public boolean addtbl_Hotels(Etbl_Hotels obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Hotels_add(?,?,?,?,?,?,?)}");
            clbStm.setString("name", obj.getName());
            clbStm.setString("address",obj.getAddress());
            clbStm.setString("phone",obj.getPhone());
            clbStm.setString("services", obj.getServices());
            clbStm.setFloat("price_range", obj.getPrice_range());
            clbStm.setInt("status", obj.getStatus());
            clbStm.setInt("locations_Id", obj.getLocations_Id());            
            clbStm.execute();
            clbStm.close();            
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Hotels.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean edittbl_Hotels(Etbl_Hotels obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Hotels_update(?,?,?,?,?,?,?,?)}");
            clbStm.setInt("hotel_Id",obj.getHotel_Id());
            clbStm.setString("name", obj.getName());
            clbStm.setString("address",obj.getAddress());
            clbStm.setString("phone",obj.getPhone());
            clbStm.setString("services", obj.getServices());
            clbStm.setFloat("price_range", obj.getPrice_range());
            clbStm.setInt("status", obj.getStatus());
            clbStm.setInt("locations_Id", obj.getLocations_Id());            
            clbStm.execute();            
            rs.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Hotels.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean deletetbl_Hotels(int hotel_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Hotels_delete(?)}");
            clbStm.setInt("hotel_Id",hotel_Id);              
            clbStm.execute();
            clbStm.close();            
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Hotels.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public Etbl_Hotels getOnetbl_Hotels(int hotel_Id){
          Etbl_Hotels obj=new Etbl_Hotels();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Hotels_get(?)}");
            clbStm.setInt("hotel_Id",hotel_Id);              
            rs=clbStm.executeQuery();            
            while(rs.next()){                            
                obj.setHotel_Id(rs.getInt("hotel_Id"));
                obj.setName(rs.getString("name"));
                obj.setAddress(rs.getString("address"));
                obj.setPhone(rs.getString("phone"));
                obj.setServices(rs.getString("services"));
                obj.setPrice_range(rs.getFloat("price_range"));
                obj.setStatus(rs.getInt("status"));
                obj.setLocations_Id(rs.getInt("locations_Id"));
                obj.setLocaltions_Name(rs.getString("locations_name"));                                        
            }
            clbStm.close();   
            rs.close();
            releaseConnection();            
            
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Hotels.class.getName()).log(Level.SEVERE, null, ex);
            
        }finally{
              return obj;
          }
      }
      
      public ArrayList getListHotels(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        try {
            ArrayList HotelsList=new ArrayList();
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Hotels_getpaged(?,?,?,?,?)}");
            clbStm.setString("OrderBy", orderBy);
            clbStm.setString("TangGiam", ASCorDESC);
            clbStm.setString("WhereClause", WhereClause);
            clbStm.setInt("PageIndex", PagingIndex);
            clbStm.setInt("PageSize", PagingSize);
            rs=clbStm.executeQuery();    
            DALTotalPageIndex.getTotalPage("tbl_Hotels", WhereClause, PagingSize);
            while(rs.next()){
                Etbl_Hotels obj=new Etbl_Hotels();
                obj.setHotel_Id(rs.getInt("hotel_Id"));
                obj.setName(rs.getString("hotel_name"));
                obj.setAddress(rs.getString("address"));
                obj.setPhone(rs.getString("phone"));
                obj.setServices(rs.getString("services"));
                obj.setPrice_range(rs.getFloat("price_range"));
                obj.setStatus(rs.getInt("status"));
                obj.setLocations_Id(rs.getInt("locations_Id"));
                obj.setLocaltions_Name(rs.getString("location_name"));  
                HotelsList.add(obj);
            }            
            clbStm.close();
            rs.close();
            releaseConnection();
            return HotelsList;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Hotels.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
      
    
}
